#plink --tfile AFFY_final_rsid_build37 --missing
#plink --tfile CGPANEL_final_build37 --missing
#plink --tfile Exome_final_updated_rsid_filtered --missing
#plink --tfile IBC_final_build37 --missing

#cat ./AFFY/plink.imiss |perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}' >./AFFY/sample.miss
#cat ./CGPANEL/plink.imiss |perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}' >./CGPANEL/sample.miss
#cat ./EXOME/plink.imiss |perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}' >./EXOME/sample.miss
#cat ./IBC/plink.imiss |perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}' >./IBC/sample.miss
#cat ./AFFY/plink.lmiss|perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}'>./AFFY/marker.miss
#cat ./CGPANEL/plink.lmiss |perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}' >./CGPANEL/marker.miss
#cat ./EXOME/plink.lmiss |perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}' >./EXOME/marker.miss
#cat ./IBC/plink.lmiss |perl -e 'while(<STDIN>){chomp($_);$_=~s/^\s+//g;$_=~s/\s+/\t/g;print $_."\n"}' >./IBC/marker.miss

#awk '{if($5 > 0.05)print $0}' ./EXOME/marker.miss > ./EXOME/QC_ind_markers.txt
#plink --tfile ./EXOME/Exome_final_updated_rsid_filtered --geno 0.1 --make-bed --out ./EXOME/Exome_final_updated_rsid_filtered_markerQC_0_01
#awk '{if($5 > 0.05)print $0}' ./CGPANEL/marker.miss >./CGPANEL/QC_ind_markers.txt
#plink --tfile ./CGPANEL/CGPANEL_final_build37 --geno 0.1 --make-bed --out ./CGPANEL/CGPANEL_final_build37_markerQC_0_01
#awk '{if($5 > 0.05)print $0}' ./AFFY/marker.miss >./AFFY/QC_ind_markers.txt
#plink --tfile ./AFFY/AFFY_final_rsid_build37 --geno 0.1 --make-bed --out ./AFFY/AFFY_final_rsid_build37_markerQC_0_01
#awk '{if($5 > 0.05)print $0}' ./IBC/marker.miss >./IBC/QC_ind_markers.txt
#plink --tfile ./IBC/IBC_final_build37 --geno 0.1 --make-bed --out ./IBC/IBC_final_build37_markerQC_0_01

awk '{if($6 > 0.1)print $1" "$2}' ./AFFY/sample.miss > ./AFFY/remove_samples.txt 
plink --bfile ./AFFY/AFFY_final_rsid_build37_markerQC_0_01 --remove ./AFFY/remove_samples.txt --make-bed --out ./AFFY/temp_remove
plink --bfile ./AFFY/AFFY_final_rsid_build37_markerQC_0_01 --keep ./AFFY/remove_samples.txt --make-bed --out ./AFFY/temp_keep
mv ./AFFY/temp_keep.bim ./AFFY/temp_keep1.bim
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"0"\t"0}' ./AFFY/temp_keep1.bim > ./AFFY/temp_keep.bim
plink --bfile ./AFFY/temp_remove --bmerge ./AFFY/temp_keep.bed ./AFFY/temp_keep.bim ./AFFY/temp_keep.fam --make-bed --out ./AFFY/AFFY_final_rsid_build37_markerQC_0_01_sampleQC_0_01
rm ./AFFY/temp_keep1.bim
rm ./AFFY/temp_keep.*
rm ./AFFY/temp_remove.*

awk '{if($6 > 0.1)print $1" "$2}' ./CGPANEL/sample.miss > ./CGPANEL/remove_samples.txt
plink --bfile ./CGPANEL/CGPANEL_final_build37_markerQC_0_01 --remove ./CGPANEL/remove_samples.txt --make-bed --out ./CGPANEL/temp_remove
plink --bfile ./CGPANEL/CGPANEL_final_build37_markerQC_0_01 --keep ./CGPANEL/remove_samples.txt --make-bed --out ./CGPANEL/temp_keep
mv ./CGPANEL/temp_keep.bim ./CGPANEL/temp_keep1.bim
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"0"\t"0}' ./CGPANEL/temp_keep1.bim > ./CGPANEL/temp_keep.bim
plink --bfile ./CGPANEL/temp_remove --bmerge ./CGPANEL/temp_keep.bed ./CGPANEL/temp_keep.bim ./CGPANEL/temp_keep.fam --make-bed --out ./CGPANEL/CGPANEL_final_build37_markerQC_0_01_sampleQC_0_01
rm ./CGPANEL/temp_keep1.bim
rm ./CGPANEL/temp_keep.*
rm ./CGPANEL/temp_remove.*


awk '{if($6 > 0.1)print $1" "$2}' ./EXOME/sample.miss > ./EXOME/remove_samples.txt
plink --bfile ./EXOME/Exome_final_updated_rsid_filtered_markerQC_0_01 --remove ./EXOME/remove_samples.txt --make-bed --out ./EXOME/temp_remove
plink --bfile ./EXOME/Exome_final_updated_rsid_filtered_markerQC_0_01 --keep ./EXOME/remove_samples.txt --make-bed --out ./EXOME/temp_keep
mv ./EXOME/temp_keep.bim ./EXOME/temp_keep1.bim
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"0"\t"0}' ./EXOME/temp_keep1.bim > ./EXOME/temp_keep.bim
plink --bfile ./EXOME/temp_remove --bmerge ./EXOME/temp_keep.bed ./EXOME/temp_keep.bim ./EXOME/temp_keep.fam --make-bed --out ./EXOME/Exome_final_updated_rsid_filtered_markerQC_0_01_sampleQC_0_01
rm ./EXOME/temp_keep1.bim
rm ./EXOME/temp_keep.*
rm ./EXOME/temp_remove.*

awk '{if($6 > 0.1)print $1" "$2}' ./IBC/sample.miss > ./IBC/remove_samples.txt
plink --bfile ./IBC/IBC_final_build37_markerQC_0_01 --remove ./IBC/remove_samples.txt --make-bed --out ./IBC/temp_remove
plink --bfile ./IBC/IBC_final_build37_markerQC_0_01 --keep ./IBC/remove_samples.txt --make-bed --out ./IBC/temp_keep
mv ./IBC/temp_keep.bim ./IBC/temp_keep1.bim
awk '{print $1"\t"$2"\t"$3"\t"$4"\t"0"\t"0}' ./IBC/temp_keep1.bim > ./IBC/temp_keep.bim
plink --bfile ./IBC/temp_remove --bmerge ./IBC/temp_keep.bed ./IBC/temp_keep.bim ./IBC/temp_keep.fam --make-bed --out ./IBC/IBC_final_build37_markerQC_0_01_sampleQC_0_01
rm ./IBC/temp_keep1.bim
rm ./IBC/temp_keep.*
rm ./IBC/temp_remove.*
